"""CreateUserTokenTable Migration."""

from masoniteorm.migrations import Migration
import os


class CreateUserTokenTable(Migration):
    def up(self):
        """
        Run the migrations.
        """
        with self.schema.create("user_tokens") as table:
            table.table_comment('会员登录态')
            table.increments("id")
            table.unsigned_integer('user_id', False)
            table.string('token', 40, False).comment('token')

            table.timestamps()
            if os.getenv("DB_CONNECTION") != "sqlite":
                table.index('user_id', 'inx_user_id')

    def down(self):
        """
        Revert the migrations.
        """
        self.schema.drop("user_tokens")
